// 测试搜索功能修复
const axios = require('axios');

async function testSearch() {
  console.log('🔍 Testing search functionality...');
  
  try {
    // 测试搜索mp-66
    const searchResponse = await axios.get('http://localhost:8002/api/materials/search?query=mp-66');
    console.log('✅ Search test passed:', searchResponse.data.results.length > 0 ? 'Found materials' : 'No results');
    
    // 测试获取材料详情
    const detailsResponse = await axios.get('http://localhost:8002/api/materials/mp-66');
    console.log('✅ Details test passed:', detailsResponse.data.material_id === 'mp-66');
    
    // 测试获取晶体结构
    const structureResponse = await axios.get('http://localhost:8002/api/materials/mp-66/structure');
    console.log('✅ Structure test passed:', structureResponse.data.material_id === 'mp-66');
    
    console.log('🎉 All tests passed! Search functionality is working correctly.');
    
  } catch (error) {
    console.error('❌ Test failed:', error.message);
    if (error.response) {
      console.error('Response status:', error.response.status);
      console.error('Response data:', error.response.data);
    }
  }
}

testSearch();